package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.OrderSms;
import com.qj.yantaishan.service.IOrderSmsService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 短信订单Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/OrderSms")
public class OrderSmsController extends BaseController
{
    private String prefix = "yantaishan/OrderSms";

    @Autowired
    private IOrderSmsService orderSmsService;

    @RequiresPermissions("yantaishan:sms:view")
    @GetMapping()
    public String sms()
    {
        return prefix + "/sms";
    }

    /**
     * 查询短信订单列表
     */
    @RequiresPermissions("yantaishan:sms:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderSms orderSms)
    {
        startPage();
        List<OrderSms> list = orderSmsService.selectOrderSmsList(orderSms);
        return getDataTable(list);
    }

    /**
     * 导出短信订单列表
     */
    @RequiresPermissions("yantaishan:sms:export")
    @Log(title = "短信订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderSms orderSms)
    {
        List<OrderSms> list = orderSmsService.selectOrderSmsList(orderSms);
        ExcelUtil<OrderSms> util = new ExcelUtil<OrderSms>(OrderSms.class);
        return util.exportExcel(list, "短信订单数据");
    }

    /**
     * 新增短信订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短信订单
     */
    @RequiresPermissions("yantaishan:sms:add")
    @Log(title = "短信订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderSms orderSms)
    {
        return toAjax(orderSmsService.insertOrderSms(orderSms));
    }

    /**
     * 修改短信订单
     */
    @RequiresPermissions("yantaishan:sms:edit")
    @GetMapping("/edit/{smsOrderId}")
    public String edit(@PathVariable("smsOrderId") Long smsOrderId, ModelMap mmap)
    {
        OrderSms orderSms = orderSmsService.selectOrderSmsBySmsOrderId(smsOrderId);
        mmap.put("orderSms", orderSms);
        return prefix + "/edit";
    }

    /**
     * 修改保存短信订单
     */
    @RequiresPermissions("yantaishan:sms:edit")
    @Log(title = "短信订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderSms orderSms)
    {
        return toAjax(orderSmsService.updateOrderSms(orderSms));
    }

    /**
     * 删除短信订单
     */
    @RequiresPermissions("yantaishan:sms:remove")
    @Log(title = "短信订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderSmsService.deleteOrderSmsBySmsOrderIds(ids));
    }
}
